package com.neuedu.his.controller;

import com.neuedu.his.po.Constantitem;
import com.neuedu.his.service.ConstantitemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/constantitem")
public class ConstantitemController {

    @Autowired
    private ConstantitemService constantitemService;

    // 新增记录
    @PostMapping
    public boolean addConstantItem(@RequestBody Constantitem constantitem) {
        return constantitemService.saveConstantItem(constantitem);
    }

    // 逻辑删除
    @DeleteMapping("/{id}")
    public boolean deleteConstantItem(@PathVariable Integer id) {
        return constantitemService.deleteLogicalById(id);
    }

    // 更新记录
    @PutMapping
    public boolean updateConstantItem(@RequestBody Constantitem constantitem) {
        return constantitemService.updateAllFields(constantitem);
    }

    // 获取常数项列表
    @GetMapping("/list")
    public List<Constantitem> listActiveItems() {
        return constantitemService.listActiveItems();
    }

    @GetMapping("/byCode/{code}")
    public Constantitem getByConstantCode(@PathVariable String code) {
        return constantitemService.findByConstantCode(code);
    }
}